Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Cmedb export shares #638

Merged
merged 5 commits into from
Sep 22, 2022
Merged

Conversation

ILightThings
Copy link
Contributor

@ILightThings ILightThings commented Sep 9, 2022

Added the ability to exports shares from cmedb.

simple

cmedb (default)(smb) > export shares simple a.csv

id,computerid,userid,name,remark,read,write
1,3,2,ADMIN$,Remote Admin,1,1
2,3,2,C$,Default share,1,1
3,3,2,DemoSystem,,1,1
4,3,2,Materclass,,1,1
5,3,2,NETLOGON,Logon server share ,1,1
6,3,2,SYSVOL,Logon server share ,1,0

detailed

cmedb (default)(smb) > export shares detailed b.csv

id,computerid,userid,name,remark,read,write
1,DC01,LIGHT\administrator,ADMIN$,Remote Admin,True,True
2,DC01,LIGHT\administrator,C$,Default share,True,True
3,DC01,LIGHT\administrator,DemoSystem,,True,True
4,DC01,LIGHT\administrator,Materclass,,True,True
5,DC01,LIGHT\administrator,NETLOGON,Logon server share ,True,True
6,DC01,LIGHT\administrator,SYSVOL,Logon server share ,True,False

@mpgn mpgn mentioned this pull request Sep 11, 2022
@mpgn mpgn linked an issue Sep 11, 2022 that may be closed by this pull request
@maaaaz
Copy link

maaaaz commented Sep 12, 2022

Thanks but please use the builtin csv Python module to ensure proper charset support.
And please quote all to avoid any escaping issue, and specify the lineterminator, for instance:
csv.writer(export_file, delimiter=";", quoting=csv.QUOTE_ALL, lineterminator='\n')

@ILightThings
Copy link
Contributor Author

Sorry about that. Out now shows the following.

cmedb (default)(smb) > export shares detailed a.csv

"id";"computerid";"userid";"name";"remark";"read";"write"
"1";"DC01";"LIGHT\administrator";"ADMIN$";"Remote Admin";"True";"True"
"2";"DC01";"LIGHT\administrator";"C$";"Default share";"True";"True"
"3";"DC01";"LIGHT\administrator";"DemoSystem";"";"True";"True"
"4";"DC01";"LIGHT\administrator";"Materclass";"";"True";"True"
"5";"DC01";"LIGHT\administrator";"NETLOGON";"Logon server share ";"True";"True"
"6";"DC01";"LIGHT\administrator";"SYSVOL";"Logon server share ";"True";"False"

@maaaaz
Copy link

maaaaz commented Sep 17, 2022

Your get_user() and get_host functions can be simplified and more robust by calling cme internal self.db.get_users/computers(arg) functions and passing args, instead of looping.

cf. #604

@ILightThings
Copy link
Contributor Author

Thank you! I did not know about this functionally. I will fix this within a few days.

@ILightThings
Copy link
Contributor Author

Sorry for the delay. The function has been fixed using @maaaaz suggestions.

@mpgn
Copy link
Contributor

mpgn commented Sep 21, 2022

All good for you @maaaaz ?

@mpgn mpgn added the in review label Sep 21, 2022
@maaaaz
Copy link

maaaaz commented Sep 22, 2022

Yes sure, thank you all.
The next step would be to rewrite all other CSV export functions (host, creds, detailed) to follow the same CSV output format

@ILightThings
Copy link
Contributor Author

ILightThings commented Sep 22, 2022

If you want, I can take the reigns one that.

You've been a huge help showing me the inner API and I time coming up I can dedicate.

@mpgn
Copy link
Contributor

mpgn commented Sep 22, 2022

I will probably merge this one this week ! Do you have a twitter @maaaaz ?

@maaaaz
Copy link

maaaaz commented Sep 22, 2022

@mpgn nope

@mpgn mpgn merged commit 2cf755d into byt3bl33d3r:master Sep 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cmedb.py - export shares
3 participants